﻿// https://mp.weixin.qq.com/s?__biz=MzUxNjY5NTYxNA==&mid=2247488961&idx=2&sn=b14c2e7b54a8e44b0135128978685a8b&scene=21#wechat_redirect
// https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci/

#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};

class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        ListNode *a = headA;
        ListNode *b = headB;
        
        while (a != b) {
            a = a != nullptr ? a->next : headA;
            b = b != nullptr ? b->next : headB;
        }
        return a;
    }
};

int main() {
    Solution obj = Solution();
}